#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string removeDuplicates(string s) {
        auto it = s.begin();
        while (it != s.end())
        {
            if (it < s.end() - 1 && *it == *(it + 1))
            {
                it = s.erase(it, it + 2);
                if (it > s.begin())--it;
            }
            else
            {
                it++;
            }
        }

        return s;
    }
};